#!/bin/bash
#
# This shell script takes care of starting and stopping Dtncpd.
# Derived from 
# http://sophie.zarb.org/distrib/Mandriva/cooker//srpms/dtn/files/7
#
# chkconfig: 345 55 45
# description: A Delay Tolerant Networking (DTN) reference implementation
# processname: dtncpd
# pidfile: /var/run/dtncpd.pid
# config: /etc/dtn.conf
# config: /etc/sysconfig/dtnd

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

DTN_HOME=/home/dorado1/mydtn

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

[ -f /usr/bin/dtncpd ] || exit 0


# See how we were called.
case "$1" in
start)
	if [ -n "`/sbin/pidof dtncpd`" ]; then
	    echo -n "DTNCP daemon already running"
	    echo
            exit 1
        fi
        cd $DTN_HOME
        /usr/bin/dtncpd incoming &> dtncpd.log &
##        /usr/bin/dtncpd $DTN_HOME/incoming &> $DTN_HOME/dtncpd.log &
#	echo -n "Starting DTNCP daemon: "
#	daemon /usr/bin/dtncpd \
#	${DTNCPD_OUTPUT:-"$DTN_HOME/incoming &>junk"} \
#	${DTNCPD_OPTIONS:-""}
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dtncpd
	;;
stop)
	echo -n "Stopping DTNCP daemon: "
	killproc dtncpd
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dtncpd
	;;
status)
	status dtncpd
	RETVAL=$?
	;;
restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
condrestart)
	[ -f /var/lock/subsys/dtncpd ] && restart
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart|condrestart|reload}"
	exit 1
esac

exit $RETVAL
